<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">

            <h:form prependId="false">

                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                <h:outputText escape="false" value="There is no customer in the system." rendered="#{customerEntityController.items.rowCount == 0}"/>
                <h:panelGroup rendered="#{customerEntityController.items.rowCount > 0}">

                    <h:outputLabel value="Please select a customer: " for="customer" />
                    <h:selectOneMenu id="customer" value="#{customerEntityController.current}" title="Select Sales Lead" >

                        <f:selectItems value="#{customerEntityController.itemsAvailableSelectOne}"/>

                    </h:selectOneMenu>
                    <h:message styleClass="errorMsg" for= "customer"/>

                    <p:commandButton value="Search"   
                                     action="#{customerEntityController.getSelected}" update="customerHistoryInquiries, customerHistoryQuotations">  
                    </p:commandButton>


                </h:panelGroup>

                <p:panel header="Sales Inquiries" id="salesInquiriesList" toggleable="true">

                    <p:dataTable id="customerHistoryInquiries" 
                                 value="#{customerEntityController.selected.salesInquiries}" 
                                 var="item" style="border:solid 1px"
                                 > 
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Sales Inquiry ID: " />  
                            </f:facet>  
                            <h:outputText value="Sales Inquiry ##{item.id}" />  
                        </p:column>
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Date Created: " />  
                            </f:facet>  
                            <h:outputText value="#{item.createdAt}" />  
                        </p:column> 

                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="" />  
                            </f:facet>           
                            <p:commandButton value="View" update ="displayInquiry, displayPqp" oncomplete="inquiryHistoryDialog.show()">  
                                <f:setPropertyActionListener value="#{item}"  
                                                             target="#{customerEntityController.salesInquiry}" /> 
                            </p:commandButton>                   
                        </p:column> 
                    </p:dataTable>

                    <p:dialog header="Customer Inquiries" widgetVar="inquiryHistoryDialog" resizable="false"  
                              width="550" showEffect="explode" hideEffect="explode">  

                        <h:panelGrid columns="7" id="displayInquiry">

                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_customer}"/>
                            <p:commandLink value="#{customerEntityController.salesInquiry.customer.firstName}&nbsp;#{customerEntityController.salesInquiry.customer.lastName}" action="#{customerEntityController.viewCustomerFromInquiryDialog}" rendered="#{customerEntityController.salesInquiry.customer!=null}" ajax="false"/>
                            <p:spacer /><p:spacer /><p:spacer />
                            <h:outputText value="Customer Id:" rendered="#{customerEntityController.salesInquiry.customer!=null}"/>
                            <h:outputText value="#{customerEntityController.salesInquiry.customer}" rendered="#{customerEntityController.salesInquiry.customer!=null}"/>

                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_createdBy}"/>
                            <h:outputText value="#{customerEntityController.salesInquiry.createdBy.firstName}&nbsp;#{customerEntityController.selected.createdBy.lastName}"/>
                            <p:spacer /><p:spacer /><p:spacer />
                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_lastModifiedBy}"/>
                            <h:outputText value="#{customerEntityController.salesInquiry.lastModifiedBy}" title="#{bundle.ViewSalesInquiryEntityTitle_lastModifiedBy}"/>

                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_createdAt}"/>
                            <h:outputText value="#{customerEntityController.salesInquiry.createdAt}" title="#{bundle.ViewSalesInquiryEntityTitle_createdAt}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                            <p:spacer /><p:spacer /><p:spacer />
                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_lastModifiedAt}"/>
                            <h:outputText value="#{customerEntityController.salesInquiry.lastModifiedAt}" title="#{bundle.ViewSalesInquiryEntityTitle_lastModifiedAt}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                            
                             <h:outputText value="ID: "/>
                            <h:outputText value="#{customerEntityController.salesInquiry.id}" title="#{bundle.ViewSalesInquiryEntityTitle_lastModifiedBy}"/>

                        </h:panelGrid>

                        <h:panelGrid id="displayPqp">
                            <p:column>
                                <h:dataTable value="#{customerEntityController.salesInquiry.pqp}" var="pqp" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Product"/>
                                        </f:facet>
                                        <h:outputText value="#{pqp.product.productName}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Quantity"/>
                                        </f:facet>
                                        <h:outputText value="#{pqp.quantity}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Price"/>
                                        </f:facet>
                                        <h:outputText value="#{pqp.price}"/>
                                    </h:column>
                                </h:dataTable>
                            </p:column>
                        </h:panelGrid>
                    </p:dialog>

                </p:panel>

            </h:form>





            <p:panel header="Sales Quotations" id="quotationList" toggleable="true">
                <h:form prependId="false">

                    <p:dataTable id="customerHistoryQuotations" 
                                 value="#{customerEntityController.selected.salesQuotations}" 
                                 var="item" style="border:solid 1px"
                                 > 
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Sales Quotation ID: " />  
                            </f:facet>  
                            <h:outputText value="Sales Quotation ##{item.id}" />  
                        </p:column>
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Date Created: " />  
                            </f:facet>  
                            <h:outputText value="#{item.createdAt}" />  
                        </p:column> 

                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="" />  
                            </f:facet>           
                            <p:commandButton value="View" update ="displayQuotation, displayPqp2" oncomplete="quotationHistoryDialog.show()">  
                                <f:setPropertyActionListener value="#{item}"  
                                                             target="#{customerEntityController.salesQuotation}" /> 
                            </p:commandButton>                   
                        </p:column> 
                    </p:dataTable>

                    <p:dialog header="Customer Quotations" widgetVar="quotationHistoryDialog" resizable="false"  
                              width="550" showEffect="explode" hideEffect="explode">  

                        <h:panelGrid columns="7" id="displayQuotation">

                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_customer}"/>
                            <p:commandLink value="#{customerEntityController.salesQuotation.customer.firstName}&nbsp;#{customerEntityController.salesQuotation.customer.lastName}" action="#{customerEntityController.viewCustomerFromQuotationDialog}" rendered="#{customerEntityController.salesQuotation.customer!=null}" ajax="false"/>
                            <p:spacer /><p:spacer /><p:spacer />
                            <h:outputText value="Customer Id:" rendered="#{customerEntityController.salesQuotation.customer!=null}"/>
                            <h:outputText value="#{customerEntityController.salesQuotation.customer}" rendered="#{customerEntityController.salesQuotation.customer!=null}"/>

                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_createdBy}"/>
                            <h:outputText value="#{customerEntityController.salesQuotation.createdBy.firstName}&nbsp;#{customerEntityController.salesQuotation.createdBy.lastName}"/>
                            <p:spacer /><p:spacer /><p:spacer />
                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_lastModifiedBy}"/>
                            <h:outputText value="#{customerEntityController.salesQuotation.lastModifiedBy}" title="#{bundle.ViewSalesInquiryEntityTitle_lastModifiedBy}"/>

                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_createdAt}"/>
                            <h:outputText value="#{customerEntityController.salesQuotation.createdAt}" title="#{bundle.ViewSalesInquiryEntityTitle_createdAt}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                            <p:spacer /><p:spacer /><p:spacer />
                            <h:outputText value="#{bundle.ViewSalesInquiryEntityLabel_lastModifiedAt}"/>
                            <h:outputText value="#{customerEntityController.salesQuotation.lastModifiedAt}" title="#{bundle.ViewSalesInquiryEntityTitle_lastModifiedAt}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                        </h:panelGrid>

                        <h:panelGrid id="displayPqp2">
                            <p:column>
                                <h:dataTable value="#{customerEntityController.salesQuotation.pqp}" var="pqp" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Product"/>
                                        </f:facet>
                                        <h:outputText value="#{pqp.product.productName}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Quantity"/>
                                        </f:facet>
                                        <h:outputText value="#{pqp.quantity}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Price"/>
                                        </f:facet>
                                        <h:outputText value="#{pqp.price}"/>
                                    </h:column>
                                </h:dataTable>
                            </p:column>
                        </h:panelGrid>
                    </p:dialog>
                </h:form>
            </p:panel>
        </ui:define>
    </ui:composition>

</html>
